home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / misc / sci / ephem_src_4_28.lha / altj.c < prev    next >
C/C++ Source or Header  |  1992-04-17  |  6KB  |  208 lines

  1. /* management and computional support for jupiter's detail menu.
  2.  */
  3.  
  4. #include <math.h>
  5. #include "astro.h"
  6. #include "circum.h"
  7. #include "screen.h"
  8.  
  9. altj_labels()
  10. {
  11.     static char grs[] = "(GRS is at approximately 30 degs in System II)";
  12.  
  13.     f_string (R_ALTM, C_ALTMV, "  Jupiter Aux");
  14.  
  15.     f_string (R_JCML, 6, "Central Meridian Longitude (degs):");
  16.     f_string (R_JCML, 51, "(Sys I)");
  17.     f_string (R_JCML, 68, "(Sys II)");
  18.     f_string (R_JCML+1, (NC-sizeof(grs))/2, grs);
  19.  
  20.     f_string (R_IO,        C_JMNAMES,    "I   Io");
  21.     f_string (R_EUROPA,    C_JMNAMES,    "II  Europa");
  22.     f_string (R_GANYMEDE,    C_JMNAMES,    "III Ganymede");
  23.     f_string (R_CALLISTO,    C_JMNAMES,    "IV  Callisto");
  24.     f_string (R_JCOLHDNGS-1,C_JMY-2,    "Jupiter Radii");
  25.     f_string (R_JCOLHDNGS,    C_JMX+1,    "X (+E)");
  26.     f_string (R_JCOLHDNGS,    C_JMY+1,    "Y (+S)");
  27.     f_string (R_JCOLHDNGS,    C_JMZ-2,    "Z (+towards)");
  28.     f_string (R_JMAP+1,    2,        "West");
  29.     f_string (R_JMAP+1,    NC-5,        "East");
  30. }
  31.  
  32. /* display jupiter's details. */
  33. /* ARGSUSED */
  34. altj_display (force, np)
  35. int force;    /* whether to print for sure or only if things have changed */
  36. Now *np;
  37. {
  38. #define    NJM    5    /* number of moons, plus + for Jupiter itself */
  39. #define    NORM    26.6    /* max callisto orbit radius; used to normalize */
  40.     static char fmt[] = "%7.3f";
  41.     struct moonxlocs {
  42.         double x;
  43.         char mid;
  44.     } raw_ml[NJM], sorted_ml[NJM];
  45.     int nml;    /* number of sorted_ml[] elements in use */
  46.     char buf[NC];
  47.     double iy, ey, gy, cy;
  48.     double iz, ez, gz, cz;
  49.     double sIcml, sIIcml;
  50.     int i;
  51.  
  52.     /* compute jupiter info.
  53.      * put moons' x loc into raw_ml[] so it can be sorted for graphic.
  54.      */
  55.     jupinfo (mjd, &raw_ml[0].x, &raw_ml[1].x, &raw_ml[2].x, &raw_ml[3].x,
  56.             &iy, &ey, &gy, &cy, &iz, &ez, &gz, &cz, &sIcml, &sIIcml);
  57.  
  58.     f_double (R_JCML, C_JCMLSI, fmt, sIcml);
  59.     f_double (R_JCML, C_JCMLSII, fmt, sIIcml);
  60.     f_double (R_IO, C_JMX, fmt, raw_ml[0].x);
  61.     f_double (R_EUROPA, C_JMX, fmt, raw_ml[1].x);
  62.     f_double (R_GANYMEDE, C_JMX, fmt, raw_ml[2].x);
  63.     f_double (R_CALLISTO, C_JMX, fmt, raw_ml[3].x);
  64.     f_double (R_IO, C_JMY, fmt, iy);
  65.     f_double (R_EUROPA, C_JMY, fmt, ey);
  66.     f_double (R_GANYMEDE, C_JMY, fmt, gy);
  67.     f_double (R_CALLISTO, C_JMY, fmt, cy);
  68.     f_double (R_IO, C_JMZ, fmt, iz);
  69.     f_double (R_EUROPA, C_JMZ, fmt, ez);
  70.     f_double (R_GANYMEDE, C_JMZ, fmt, gz);
  71.     f_double (R_CALLISTO, C_JMZ, fmt, cz);
  72.  
  73.     raw_ml[0].mid = 'I';
  74.     raw_ml[1].mid = 'E';
  75.     raw_ml[2].mid = 'G';
  76.     raw_ml[3].mid = 'C';
  77.     raw_ml[4].x = 0.0;
  78.     raw_ml[4].mid = 'J';
  79.  
  80.     /* insert in increasing order into sorted_ml[]
  81.      */
  82.     nml = 0;
  83.     for (i = 0; i < NJM; i++) {
  84.         int j;
  85.         /* exit loop with next sort_ml location to use at index j+1 */
  86.         for (j = nml; --j >= 0; )
  87.         if (raw_ml[i].x < sorted_ml[j].x)
  88.             sorted_ml[j+1] = sorted_ml[j];
  89.         else
  90.             break;
  91.         sorted_ml[j+1] = raw_ml[i];
  92.         nml++;
  93.     }
  94.  
  95.     /* blank-fill and terminate buf */
  96.     (void) sprintf (buf, "%*s", NC-1, "");
  97.  
  98.     /* convert to screen columns, maintaining correct left-to-right
  99.      * order based on x when there are collisions.
  100.      */
  101.     for (i = 0; i < NJM; i++) {
  102.         int col = (int)(NC/2-1 + (NC/2-1)*sorted_ml[i].x/NORM + 0.5);
  103.         while (buf[col] != ' ')
  104.         col++;
  105.         buf[col] = sorted_ml[i].mid;
  106.     }
  107.  
  108.     f_string (R_JMAP, C_JMAP, buf);
  109. }
  110.  
  111. #define    dsin(x)    sin(degrad(x))
  112. #define    dcos(x)    cos(degrad(x))
  113.  
  114. /* given a modified julian date (ie, days since Jan .5 1900), d, return x, y, z
  115.  *   location of each Galilean moon as a multiple of Jupiter's radius. on this
  116.  *   scale, Callisto is never more than 26.5593. +x is easterly, +y is
  117.  *   southerly, +z is towards earth. x and z are relative to the equator
  118.  *   of Jupiter; y is further corrected for earth's position above or below
  119.  *   this plane. also, return the system I and II central meridian longitude,
  120.  *   in degress, relative to the true disk of jupiter and corrected for light
  121.  *   travel time.
  122.  * from "Astronomical Formulae for Calculators", 2nd ed, by Jean Meeus,
  123.  *   Willmann-Bell, Richmond, Va., U.S.A. (c) 1982, chapters 35 and 36.
  124.  */
  125. static
  126. jupinfo (d, ix, ex, gx, cx, iy, ey, gy, cy, iz, ez, gz, cz, sIcml, sIIcml)
  127. double d;
  128. double *ix, *ex, *gx, *cx;
  129. double *iy, *ey, *gy, *cy;
  130. double *iz, *ez, *gz, *cz;
  131. double *sIcml, *sIIcml;
  132. {
  133.     double A, B, Del, J, K, M, N, R, V;
  134.     double cor_u1, cor_u2, cor_u3, cor_u4;
  135.     double solc, tmp, G, H, psi, r, r1, r2, r3, r4;
  136.     double u1, u2, u3, u4;
  137.     double lam, Ds;
  138.     double z1, z2, z3,  z4;
  139.     double De, dsinDe;
  140.  
  141.     V = 134.63 + 0.00111587 * d;
  142.  
  143.     M = (358.47583 + 0.98560003*d);
  144.     N = (225.32833 + 0.0830853*d) + 0.33 * dsin (V);
  145.  
  146.     J = 221.647 + 0.9025179*d - 0.33 * dsin(V);;
  147.  
  148.     A = 1.916*dsin(M) + 0.02*dsin(2*M);
  149.     B = 5.552*dsin(N) + 0.167*dsin(2*N);
  150.     K = (J+A-B);
  151.     R = 1.00014 - 0.01672 * dcos(M) - 0.00014 * dcos(2*M);
  152.     r = 5.20867 - 0.25192 * dcos(N) - 0.00610 * dcos(2*N);
  153.     Del = sqrt (R*R + r*r - 2*R*r*dcos(K));
  154.     psi = raddeg (asin (R/Del*dsin(K)));
  155.  
  156.     solc = (d - Del/173.);    /* speed of light correction */
  157.     tmp = psi - B;
  158.  
  159.     u1 = 84.5506 + 203.4058630 * solc + tmp;
  160.     u2 = 41.5015 + 101.2916323 * solc + tmp;
  161.     u3 = 109.9770 + 50.2345169 * solc + tmp;
  162.     u4 = 176.3586 + 21.4879802 * solc + tmp;
  163.  
  164.     G = 187.3 + 50.310674 * solc;
  165.     H = 311.1 + 21.569229 * solc;
  166.       
  167.     cor_u1 =  0.472 * dsin (2*(u1-u2));
  168.     cor_u2 =  1.073 * dsin (2*(u2-u3));
  169.     cor_u3 =  0.174 * dsin (G);
  170.     cor_u4 =  0.845 * dsin (H);
  171.       
  172.     r1 = 5.9061 - 0.0244 * dcos (2*(u1-u2));
  173.     r2 = 9.3972 - 0.0889 * dcos (2*(u2-u3));
  174.     r3 = 14.9894 - 0.0227 * dcos (G);
  175.     r4 = 26.3649 - 0.1944 * dcos (H);
  176.  
  177.     *ix = -r1 * dsin (u1+cor_u1);
  178.     *ex = -r2 * dsin (u2+cor_u2);
  179.     *gx = -r3 * dsin (u3+cor_u3);
  180.     *cx = -r4 * dsin (u4+cor_u4);
  181.  
  182.     lam = 238.05 + 0.083091*d + 0.33*dsin(V) + B;
  183.     Ds = 3.07*dsin(lam + 44.5);
  184.     De = Ds - 2.15*dsin(psi)*dcos(lam+24.)
  185.         - 1.31*(r-Del)/Del*dsin(lam-99.4);
  186.     dsinDe = dsin(De);
  187.  
  188.     z1 = r1 * dcos(u1+cor_u1);
  189.     z2 = r2 * dcos(u2+cor_u2);
  190.     z3 = r3 * dcos(u3+cor_u3);
  191.     z4 = r4 * dcos(u4+cor_u4);
  192.  
  193.     *iy = z1*dsinDe;
  194.     *ey = z2*dsinDe;
  195.     *gy = z3*dsinDe;
  196.     *cy = z4*dsinDe;
  197.  
  198.     *iz = z1;
  199.     *ez = z2;
  200.     *gz = z3;
  201.     *cz = z4;
  202.  
  203.     *sIcml  = 268.28 + 877.8169088*(d - Del/173) + psi - B;
  204.     range (sIcml, 360.0);
  205.     *sIIcml = 290.28 + 870.1869088*(d - Del/173) + psi - B;
  206.     range (sIIcml, 360.0);
  207. }
  208.